package com.zicheng.thread.demo;

import org.junit.jupiter.api.Test;

/**
 * @author wzy
 */
public class DemoTaskTests {

    /**
     * 1.继承Thread的方式
     * <pre>
     *     demoTask1 extends Thread{
     *         task(){
     *         sout("it`s work!")
     *         }
     *
     *         run(){
     *             task();
     *         }
     *     }
     * </pre>
     * <p>
     *     this is p
     * </p>
     * <code>java.long.Thread</code>
     * @see  java.lang.Thread
     */
    @Test
    public void testDemoTaskOne1() {
        DemoTaskOne demoTask1 = new DemoTaskOne();
        System.out.println(demoTask1.isAlive());
        demoTask1.setName("Thread-1");
        System.out.println(demoTask1.getName());
        demoTask1.start();
        System.out.println(demoTask1.isAlive());
        System.out.println(demoTask1.getId());
        DemoTaskOne demoTask2 = new DemoTaskOne();
        System.out.println(demoTask1.isAlive());
        System.out.println(demoTask2.getName());
        System.out.println(demoTask2.getId());
        System.out.println(demoTask1.isAlive());
    }

    @Test
    public void testDemoTaskOne2() throws InterruptedException {
        System.out.println(Thread.currentThread().getName() + " : " + Thread.currentThread().getId() + " is running");
        DemoTaskTwo demoTask1 = new DemoTaskTwo();
        System.out.println(demoTask1.getState());
        demoTask1.start();
        System.out.println(demoTask1.getState());
    }
}
